/* 
  Copyright (c) SilverLining 2015
  Date:    2016-1-17
  File:    MessageType.cpp  
  Description: 
	Contains the definition of the MessageType class.
*/

#include "stdafx.h"

using namespace System;
using namespace System::Runtime::Serialization;

#include "MessageType.h"

bool SL::M::MessageType::Equals(Object ^ obj)
{
	if ((Object^)obj != nullptr && obj->GetType() == MessageType::typeid)
	{
		return Equals((MessageType^)obj);
	}
	return Object::Equals(obj);
}

int SL::M::MessageType::GetHashCode()
{
	return _type->GetHashCode();
}

String ^ SL::M::MessageType::ToString()
{
	return _type;
}

bool SL::M::MessageType::Equals(SL::M::MessageType ^ other)
{
	if ((Object^)this != other && other != nullptr)
	{
		return _type->Equals(other->_type);
	}
	return true;
}

SL::M::MessageType^ SL::M::MessageType::Get(String ^ typeName)
{
	return gcnew MessageType(typeName);
}

SL::M::MessageType::operator MessageType ^ (String ^ messageType)
{
	return gcnew MessageType(messageType);
}

void SL::M::MessageType::GetObjectData(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context)
{
	info->AddValue("Type", _type);
}

SL::M::MessageType::MessageType(SerializationInfo ^ info, StreamingContext context)
{
	_type = (String^)info->GetValue("Type", String::typeid);
}

SL::M::MessageType::MessageType(String ^ typeName)
{
	if (String::IsNullOrEmpty(typeName))
	{
		throw gcnew ArgumentException("Argument cannot be null or empty.", "typeName");
	}
	_type = typeName;
}


